import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Printer {
	private Lock mLock = new ReentrantLock();
	private Random mRandom = new Random();

	public void print() {
		boolean tryLock = mLock.tryLock();
		if (tryLock) {
			try {
				System.out.printf("current date %4dms\n",
						System.currentTimeMillis());
				Thread.sleep(mRandom.nextInt(200));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				mLock.unlock();
			}

		} else {
			System.out.println("printer is occupied");
		}

	}

}
